<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        ul {
            width: 1200px;
            margin: auto;
            display: flex;
            flex-wrap: wrap;
        }

        li {
            width: 23%;
            margin: 1%;
            border: 1px solid #000;
            box-sizing: border-box;
            text-align: center;
        }

        img {
            width: 80%;
        }

        .search {
            width: 1200px;
            margin: auto;
            display: flex;
            justify-content: center;
            margin-bottom: 30px;
        }
    </style>
</head>

<body>

    <div class="search">
        <input type="text">
        <button>搜索一下</button>
    </div>


    <ul>
        <!-- <li>
            <img src="" alt="">
            <h3></h3>
            <p></p>
            <span></span>
        </li> -->
    </ul>


    <script>

        var data = [
            {
                bioaTi: 'xiao mi',
                des: '徕卡光学全焦段四摄| 一英寸可变光圈| 徕卡专业街拍模式',
                img: 'https://cdn.cnbj1.fds.api.mi-img.com/nr-pub/202304171459_dd35f1e6215da63c356e352d4d398ce6.png?thumb=1&w=188&h=188&f=webp&q=90',
                price: 299
            },
            {
                bioaTi: '华为手机',
                des: '徕卡光学全焦段四摄| 一英寸可变光圈| 徕卡专业街拍模式',
                img: 'https://cdn.cnbj1.fds.api.mi-img.com/nr-pub/202304171459_dd35f1e6215da63c356e352d4d398ce6.png?thumb=1&w=188&h=188&f=webp&q=90',
                price: 5999
            },
            {
                bioaTi: '华为手机 青春版',
                des: '徕卡光学全焦段四摄| 一英圈| 徕卡专业街拍模式',
                img: 'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/8b046feca0a7bb3f7b961a9690babb1b.jpg?thumb=1&w=188&h=188&f=webp&q=90',
                price: 5999
            },
            {
                bioaTi: 'xiao mi2',
                des: '徕卡光学全焦段四摄| 一英寸可变光圈| 徕卡专业街拍模式',
                img: 'https://cdn.cnbj1.fds.api.mi-img.com/nr-pub/202304171459_dd35f1e6215da63c356e352d4d398ce6.png?thumb=1&w=188&h=188&f=webp&q=90',
                price: 5999
            }
        ];




        // 渲染页面
        render(data);



        // 搜索功能
        //     给按钮绑定点击事件   获取输入框的值

        var oInp = document.querySelector('input');
        var oBtn = document.querySelector('button');

        // 
        oBtn.onclick = function () {
            // 获取输入框的值
            var key = oInp.value;
            // console.log(key);

            // 搜索的实现：过滤数据 filter
            var res = data.filter(function (v) {
                // return 条件
                return v.bioaTi.includes(key);
            })

            // console.log(res);


            // 渲染页面
            render(res);
        }







        function render(arr) {
            var oUl = document.querySelector('ul');

            var html = '';
            arr.forEach(function (v) {
                html += `
            <li>
                <img src="${v.img}" alt="">
                <h3>${v.bioaTi}</h3>
                <p>${v.des}</p>
                <span>${v.price}</span>
            </li> 
            `
            })

            oUl.innerHTML = html;
        }


    </script>

</body>

</html>